package com.fts.admin.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一返回数据结构
 * @author xlwang
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {
    private Integer status;
    private String message;
    private T data;

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }

    public static <T> ResponseResult<T> success(String message, T data) {
        return new ResponseResult<>(ResultEnum.SUCCESS.getCode(), message, data);
    }

    public static ResponseResult<?> failed() {
        return new ResponseResult<>(ResultEnum.COMMON_FAILED.getCode(), ResultEnum.COMMON_FAILED.getMessage(), null);
    }

    public static ResponseResult<?> failed(String message) {
        return new ResponseResult<>(ResultEnum.COMMON_FAILED.getCode(), message, null);
    }

    public static ResponseResult<?> failed(IResultInfo errorResult) {
        return new ResponseResult<>(errorResult.getCode(), errorResult.getMessage(), null);
    }

    public static ResponseResult<?> failed(Integer code, String message) {
        return new ResponseResult<>(code, message, null);
    }

    public static <T> ResponseResult<T> instance(Integer code, String message, T data) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setStatus(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }
}
